<?php

namespace app\Admin\controller;

use app\Admin\model\User;
use think\Controller;
use think\Request;

class Login extends Controller
{
    public  function index()
    {
        return view('login/index');
    }

    public  function signIn(Request $request)
    {
        $data = input('post.');

        $rule = [
            'username'=>'require',
            'password'=>'require'
        ];
        $msg = [
            'username.require'=>'用户名必须填写',
            'password.require'=>'密码必须填写',
        ];

        $validateRes = $this->validate($data,$rule,$msg);

        if ($validateRes !==true){
            $this->error($validateRes);
        }

        //查询数据库
        $login_data = User::get($data);
        if ($login_data == null){
            $this->error('用户名或密吗错误');
        }else{
            session('user',$login_data->id);
            $this->redirect('admin/information/type_list');
        }
    }
}
